package com.dgut.service.background.service;

import com.dgut.service.background.dao.EnterDao;
import com.dgut.service.background.entity.Enter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class EnterService {
    @Autowired
    private EnterDao enterDao;

    public Page<Enter> findAllEnter(int page){
        Pageable pageable = PageRequest.of(page, 10);
        return enterDao.findAll(pageable);
    }

    public Page<Enter> findAllOuts(Pageable pageable){
        return enterDao.findAll(pageable);
    }

    public Page<Enter> findByDate(String date1,String date2, Pageable pageable){
        return enterDao.findAllByTimesBetween(date1,date2,pageable);
    }

    public Page<Enter> findAllByTimesBetweenAndUsernameLike(String username, String[] towDate, Pageable pageable){
        return enterDao.findAllByTimesBetweenAndUsernameLike(towDate[0], towDate[1], username, pageable);
    }

    public Page<Enter> findAllByUsername(String username, Pageable pageable){
        return enterDao.findAllByUsername(username, pageable);
    }
}
